package semantic.analyzer;

import metamodel.PrimitiveTypeEnum;
import semantic.SemanticException;
import semantic.model.ExpressionNode;
import semantic.model.UndefinedExpressionNode;

public class LogicalExpressionAnalyzer {

	public static void checkConcordance(ExpressionNode node1, ExpressionNode node2) {
		if (node2 != null && node1.getType().equalsIgnoreCase(PrimitiveTypeEnum.UNDEFINED.name())) {
			UndefinedExpressionNode node = (UndefinedExpressionNode) node1;
			node.setTypeItShouldBe(node2.getType());
		} else if ((node2 != null) && (node1.getType() != node2.getType())) {
			throw new SemanticException("Inconformidade de tipos: " + node1.getType() + " != " + node2.getType());
		} else if ((node2 == null)&&(node1.getType().equalsIgnoreCase(PrimitiveTypeEnum.UNDEFINED.name()))) {
			UndefinedExpressionNode uNode = (UndefinedExpressionNode) node1;
			if (uNode.getTypeItShouldBe() == null){
				uNode.setTypeItShouldBe(PrimitiveTypeEnum.BOOLEAN.name());
			}
		}
			
	}

}
